<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;

class AssetsDetailed extends Admin
{
    protected $table_id = false;
    public function initialize()
    {
        $this->menu_input = [
            'all' => [
                ['type' => 'text', 'name' => '标题', 'key' => 'title','verify'=>'required'],
                ['type' => 'text', 'name' => '内容', 'key' => 'value','verify'=>'required'],
            ],
            'add' => [

            ],
            'upload' => [

            ],
        ];
        parent::initialize(); // TODO: Change the autogenerated stub
    }
    public function table_mage(&$data = [])
    {
        $data = [
            ['field' => 'create_time', 'title' => '时间'],
            ['field' => 'type', 'title' => '类型'],
            ['field' => 'js_money', 'title' => '结算'],
        ];
        return parent::table_mage($data); // TODO: Change the autogenerated stub
    }
    public function index_handle(&$data)
    {
        $data['data'] = array_map(function($v){
            if($v['type'] == 1){
                $v['type'] = '用户下单';
            }elseif($v['type'] == 2){
                $v['type'] = '操作结算';
            }else{
                $v['type'] = '购买会员';
            }
            $v['js_money'] = '<p style="color: #00a2d4">+'.$v['money'].'(实际收益：'.$v['sj_money'].')</p>';
            return $v;
        },$data['data']);
        return parent::index_handle($data); // TODO: Change the autogenerated stub
    }
    public function index_where(&$where)
    {
        if(!empty($where) && is_array($where)){
            foreach ($where as $k=>$v){
                if($v[0] == 'time_time'){
                    $time = explode('到',$v[2]);
                    $where[] = ['create_time','>=',trim($time[0])];
                    $where[] = ['create_time','<=',trim($time[1])];
                    unset($where[$k]);
                }
            }
        }
        return parent::index_where($where); // TODO: Change the autogenerated stub
    }
}
